<template>
    <div>
        <div class="operation">
            <a class="btn btn-theme" @click="showAddFuncModal">新增权限</a>
            <a class="btn btn-theme" @click="showModifyFuncModal">编辑权限</a>
            <a class="btn btn-theme" @click="showDeleteFuncModal">删除权限</a>
        </div>
        <table class="table">
            
        </table>
        <div class="modal fade" id="function_add_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="exampleModalLabel">添加功能</h4>
                                </div>
                                <div class="modal-body">
                                    <form>
                                        <div class="form-group">
                                            <label for="function_add_parentid" class="control-label">父ID：</label>
                                            <input type="text" placeholder="0" class="form-control" id="function_add_parentid">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_add_name" class="control-label">功能名称：(*.html,*;必填)</label>
                                            <input type="text" class="form-control" id="function_add_name">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_add_type" class="control-label">类型：(page,or...)</label>
                                            <input type="text" class="form-control" id="function_add_type">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_add_application" class="control-label">应用：(web,or...)</label>
                                            <input type="text" class="form-control" id="function_add_application">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_add_fnotes" class="control-label">备注</label>
                                            <input type="text" class="form-control" id="function_add_fnotes">
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" @click="addFunc">提交</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="modal fade" id="function_modify_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="exampleModalLabel">修改功能</h4>
                                </div>
                                <div class="modal-body">
                                    <form>
                                        <div class="form-group">
                                            <label for="function_modify_parentid" class="control-label">父ID：</label>
                                            <input type="text" class="form-control" id="function_modify_parentid">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_modify_name" class="control-label">功能名称：(*.html,*;必填)</label>
                                            <input type="text" class="form-control" id="function_modify_name">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_modify_type" class="control-label">类型：(page,or...)</label>
                                            <input type="text" class="form-control" id="function_modify_type">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_modify_application" class="control-label">应用：(web,or...)</label>
                                            <input type="text" class="form-control" id="function_modify_application">
                                        </div>
                                        <div class="form-group">
                                            <label for="function_modify_fnotes" class="control-label">备注</label>
                                            <input type="text" class="form-control" id="function_modify_fnotes">
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    <button type="button" class="btn btn-primary" @click="modifyFunc">提交</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="modal fade" id="function_drop_modal">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title">删除确定</h4>
                                </div>
                                <div class="modal-body">
                                    <p>您真的要删除此功能吗？</p>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                    <button type="button" class="btn btn-primary" @click="deleteFunc">确认</button>
                                </div>
                            </div>
                        </div>
                    </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {

            }
        },
        methods: {
            getTable() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/scfunctions/fetchalllist',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        $('.table').bootstrapTable('destroy')
                        $('.table').bootstrapTable({
                            data: retdata.Table2,
                            columns: [{
                                radio: true,
                            }, {
                                field: 'fidno',
                                title: '编号',
                                halign: 'center'
                            }, {
                                field: 'fnotes',
                                title: '功能名称',
                                halign: 'center'
                            }, {
                                field: 'ftype',
                                title: '类型',
                                halign: 'center'
                            }, {
                                field: 'functionname',
                                title: 'url',
                                halign: 'center'
                            }],
                            pagination: true,
                            paginationLoop: true,
                            onlyInfoPagination: false,
                            striped: true,
                            sidePagination: 'client',
                            pageNumber: 1,
                            pageSize: 10,
                            pageList: [10, 25, 50, 100],
                            smartDisplay: true,
                            search: true,
                            searchOnEnterKey: false,
                            strictSearch: false,
                            showHeader: true,
                            //showFooter: true,
                            showColumns: true,
                            showRefresh: true,
                            // showToggle: true,
                            showPaginationSwitch: true,
                            //detailView: true,
                            clickToSelect: true,
                            singleSelect: true,
                            //checkboxHeader: true,
                            radio: true,
                            //checkbox: true,
                            //clickToSelect: true,
                        });
                    }
                });
            },
            showAddFuncModal() {
                $('#function_add_modal').modal('show')
            },
            showModifyFuncModal() {
                var _this = this
                $('#function_modify_modal').modal('show')
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/scfunctions/fetchlistbyid',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fidno': $('input:radio:checked').parent().next().text()
                    },
                    async: true,
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        $('#function_modify_parentid').val(retdata.Table2[0].fparentidno);
                        $('#function_modify_name').val(retdata.Table2[0].functionname);
                        $('#function_modify_type').val(retdata.Table2[0].ftype);
                        $('#function_modify_application').val(retdata.Table2[0].fapplication);
                        $('#function_modify_fnotes').val(retdata.Table2[0].fnotes)
                    }
                });
            },
            showDeleteFuncModal() {

                $('#function_drop_modal').modal('show')
            },
            addFunc() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/scfunctions/add',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fparentidno': $('#function_add_parentid').val(),
                        'fapplication': $('#function_add_application').val(),
                        'ftype': $('#function_add_type').val(),
                        'functionname': $('#function_add_name').val(),
                        'fnotes': $('#function_add_fnotes').val()
                    },
                    async: true,
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        if (retdata.Table1[0].message == 'ok') {
                            $('#function_add_modal').modal('hide');
                            _this.getTable()
                        }
                    }
                });
            },
            modifyFunc() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/scfunctions/update',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fidno': $('input:radio:checked').parent().next().text(),
                        'fparentidno': $('#function_modify_parentid').val(),
                        'fapplication': $('#function_modify_application').val(),
                        'ftype': $('#function_modify_type').val(),
                        'functionname': $('#function_modify_name').val(),
                        'fnotes': $('#function_modify_fnotes').val()
                    },
                    async: true,
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        $('#function_modify_modal').modal('hide');
                        _this.getTable()
                    }
                });
            },
            deleteFunc() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/scfunctions/delete',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fidno': $('input:radio:checked').parent().next().text()
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        $('#function_drop_modal').modal('hide');
                        _this.getTable()
                    }
                });
            }
        },
        mounted() {
            this.getTable()
        }
    }
</script>
<style>

</style>